<%@ page language="java" session="true" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<jsp:include page="../common/framework/header.jsp" />
<link href="${pageContext.request.contextPath}/static/plugin/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
<style type="text/css">
	select.form-control {
	    height: 32px;
	    padding: 4px 6px;
	    width: 200px!important;
	}
	.bs-bars{padding:0;}
	.row {
    margin: 0;
	}
</style>
	<div id="container"
		class="effect aside-float aside-bright mainnav-lg navbar-fixed mainnav-fixed aside-fixed">

		<jsp:include page="../common/framework/topper.jsp" />
		<div class="boxed">
			<%--=======================  页面主体内容  ============================--%>
			<div id="content-container">
				<div class="wrappers">
					<%--=========================  页面标题  ==========================--%>
					<div id="page-title">
						<p class="page-header text-overflow table-header">
							参数规则&nbsp;&nbsp;<small>本页面展示接口参数的规则。详细说明请参考
							<a href="http://confluence.paas.sinopec.com/pages/viewpage.action?pageId=11343322#id-使用手册-_Toc471811871" target="_blank">&lt;使用手册&gt;</a></small>
						</p>
					</div>
					<ol class="breadcrumb">
						<li><a href="#">测试助手</a></li>
						<li class="active">参数规则</li>
					</ol>
					<div id="page-content">
						<div class="panel">
							<div class="panel-body pad-top-no">
								<div id="toolbar">
									<form id="search_form" class="form-inline" autocomplete="off">

										<label class="control-label width-auto" for="appName">规则名称:</label>
										<div class="input-group">
											<input id="appName" name="appName" type="text" placeholder="请输入" class="form-control">
										  	<span class="input-group-btn" onclick="searchForm();">
												<a class="btn btn-icon btn-hover-primary" type="button" style="margin-right: 15px;">
													<i class="fa fa-search" ></i>
												</a>
											</span>
										</div>

										<label class="control-label width-auto" for="appName">规则编码:</label>
										<div class="input-group">
											<input id="appName" name="appName" type="text" placeholder="请输入" class="form-control">
										  	<span class="input-group-btn" onclick="searchForm();">
												<a class="btn btn-icon btn-hover-primary" type="button" style="margin-right: 15px;">
													<i class="fa fa-search" ></i>
												</a>
											</span>
										</div>

										<label class="control-label width-auto" for="appGroup">规则样板:</label>
										<select class="form-control" id="appGroup" name="appGroup">
											<option value="">请选择分组</option>

												<option value="edas">edas</option>

												<option value="xyt">xyt</option>

										</select>

										<a id = "reset" class = "btn btn-gray" style="margin-top: 2px;"><i class="glyphicon glyphicon-share-alt"></i>重置</a>

										<a class="btn btn-primary pull-right" id="insert" style="margin-top: 2px;">
											<i class="fa fa-plus"></i>添加
										</a>

									</form>
								</div>
                                  <table id="mockRuleTable" class="table" data-single-select="true" data-toolbar="#toolbar"
               						 data-buttons-class="hover-primary">
                                      <thead>
								        <tr>
								            <th data-field="state" data-checkbox="true"></th>
								            <th data-field="ruleNm">规则名称</th>
								            <th data-field="ruleCode" >规则编码</th>
								            <th data-field="rulePattern" >规则样板</th>
								            <th data-align="center" data-width="140" data-formatter="pref_btns">操作</th>
								        </tr>
								    </thead>
                                  </table>
							</div>
						</div>

			</div>
		</div>
	</div>


	<div id ="addOrEditMockRuleHtml" style="display:none;">
		<form id ="mockRuleForm">
		    <div class = "row" style = "margin-top : 20px;padding-right:15px;">
		         <div class = "form-group col-sm-12 col-xs-12" >
		            <label class="col-xs-2" style="padding:6px 0 0 0;text-align:right;"><font color=red>*</font>规则名称:</label>
					<div class="col-xs-10" style="padding-right:0;">
						<input type = "text" class="  form-control" id="ruleNm" name = "ruleNm" placeholder = "请输入规则名称">
		         	</div>
		         </div>
		     </div>
		      <div class = "row" style="padding-right:15px;">
		         <div class = "form-group col-sm-12 col-xs-12" >
		            <label class="col-xs-2" style="padding:6px 0 0 0;text-align:right;"><font color=red>*</font>规则编码:</label>
		            <div class="col-xs-10" style="padding-right:0;">
						<input type = "text" class="  form-control" id="ruleCode" name = "ruleCode">
					 </div>
		         </div>
		     </div>
		     <div class=" row"  style="padding-right:15px;">
		     	<div class = "form-group col-sm-12 col-xs-12" >
		            <label class="col-xs-2" style="padding:6px 0 0 0;text-align:right;"><font color=red>*</font>规则样板:</label>
		            <div class="col-xs-10" style="padding-right:0;">
		            	<input type = "text" class="  form-control" id="rulePattern" name = "rulePattern" placeholder = "请输入规则名称">
		            (例：@randomDigit(num)、@autoIncrement(start,step)等)
		             </div>
		         </div>
		      </div>
		    </form>
		</div>
		<%--=========================  过程可视化消息栏  ==========================--%>
		<jsp:include page="../common/framework/aside.jsp" />

		<%--=========================  左侧菜单  ==========================--%>
		<jsp:include page="../common/framework/lefter.jsp" />

	</div>

	<%--=========================  页面底部版权信息  ==========================--%>
	<jsp:include page="../common/framework/footer.jsp" />
	<%--=========================  选择皮肤功能  ==========================--%>
	<jsp:include page="../common/framework/page-set.jsp" />
</div>
	<div id="floating-top-right" class="floating-container"></div>
<%--===================================================--%>
<%-- END OF CONTAINER --%>

<jsp:include page="../common/framework/script.jsp" />
	<script src="${pageContext.request.contextPath}/static/js/common/bootdatatable.init.js"></script>
	<script src="${pageContext.request.contextPath}/static/plugin/bootstrap-table/bootstrap-table.min.js"></script>
	<script src="${pageContext.request.contextPath}/static/plugin/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>


	<script type="text/javascript">

	//初始化
	$(function(){
	/*表单验证  */
	//表单验证
		 $('#mockRuleForm').bootstrapValidator({
	   		   message: 'This value is not valid',
	           feedbackIcons: {
	        	   valid:'glyphicon glyphicon-ok',
	        	   invalid:'glyphicon glyphicon-remove',
	        	   validating:'glyphicon glyphicon-refresh'
	           },
	           excluded: [':read-only'],
	            fields: {
	            	ruleNm :{
						message : '套件名称验证失败',
						validators : {
							notEmpty : {//非空验证：提示消息
								message : '套件名称不能为空'
							},
							stringLength: {/*长度提示*/
							    min: 1,
							    max: 32,
							    message: '名称不能超过32个字符'
							   }
						}
					},
					ruleCode :{
						message : '套件名称验证失败',
						validators : {
							notEmpty : {//非空验证：提示消息
								message : '套件名称不能为空'
							},
							stringLength: {/*长度提示*/
							    min: 1,
							    max: 100,
							    message: '模块编码不能超过100个字符'
							   }
						}
					},
					rulePattern :{
						message : '套件名称验证失败',
						validators : {
							notEmpty : {//非空验证：提示消息
								message : '套件名称不能为空'
							},
							stringLength: {/*长度提示*/
							    min: 1,
							    max: 100,
							    message: '套件名称长度必须在1到100个字之间'
							   }
						}
					}

	               }
	        });
	})
$(function() {
	//加载表格
	$('#mockRuleTable').bootdatagrid(
			"${pageContext.request.contextPath}/static/plugin/bootstrap-table/staticData/mockRule.json", {
				pagination : true,
				pageNumber : 1,
				pageSize : 10,
				dataType:'json',
				singleSelect : false,
				striped : true,
				clickToSelect : true
	});

})
function invoiceFormatter(value,row,index){
	return 'ID '+value;
}
function pref_btns(value,row,index){
	var btns = '';
	btns += '<a class="btn-table-cell" onclick="addOrEditMockRule('+index+');">编辑</a>';
	btns += ' | <a class="btn-table-cell" data-toggle="tooltip" data-container="body" data-placement="top" title="日志日志">删除</a>';
	return btns;
}

function tablebtnclick(e){
	Alert.success($(e).text());
}

//添加按钮
$("#insert").click(function(){
	var index = -1;
	addOrEditMockRule(index);
});
function addOrEditMockRule(index){
	$('#mockRuleForm').data('bootstrapValidator').resetForm(true);
	 if(index != -1){
	    	row = $("#mockRuleTable").bootstrapTable('getData')[index];;
	    	//编辑时，取出参数显示在编辑框
	    	ruleNm = row.ruleNm;
	    	if(ruleNm)
	    		document.getElementById("ruleNm").value = ruleNm;
	    	//编辑时，取出参数显示在编辑框
	    	ruleCode = row.ruleCode;
	    	if(ruleCode)
	    		document.getElementById("ruleCode").value = ruleCode;
	    	//编辑时，取出配置参数显示在编辑框
	    	rulePattern = row.rulePattern;
	    	if(rulePattern)
	    		document.getElementById("rulePattern").value = rulePattern;
	    }else{
	    	document.getElementById("ruleNm").value = "";
	    	document.getElementById("ruleCode").value = "";
	    	document.getElementById("rulePattern").value = "";
	    }
	layer.open({
		type : 1,
		title : (index != -1) ? '编辑规则' : '添加规则',
		fix : true,
		scrollbar : false,
// 		maxmin: true, //开启最大化最小化按钮
		area : [ '550px', '320px' ],
		shift : 2,
		content : $('#addOrEditMockRuleHtml'),
		btn:['确定','取消'],
		success: function(layero, index){
			if(!$('.layui-layer-title').has('span').length){
				 $(".layui-layer-title").prepend("<span class='glyphicon glyphicon-th-large' ></span>&nbsp;");
			 }
	  	},
		end : function() {
		},
		yes: function(index, layero){
// 				saveLink();//保存
		  },
		btn2: function(index, layero){
		    //按钮【按钮二】的回调
		  },
	});
	};
</script>
</body>
</html>

